<template>
	<el-card shadow="hover">
		<template v-slot:header>
			文件柜
			<div style="float: right;display: inline-flex;color: #FFFFFF;">
				<sc-icon style="cursor: pointer;width: 18px; margin-right: 10px;" @click="reLoadPublicFile" title="刷新"><el-icon-refresh-right/></sc-icon>
				<sc-icon style="cursor: pointer;width: 18px;" @click="getMorePublicFile" title="全部"><el-icon-more-filled/></sc-icon>
			</div>

		</template>
		<div style="height: 210px;text-align: center;cursor: pointer">
			<el-row :gutter="15">
				<div class="el-table__empty-block" style="background-color: #f6f8f9" v-if="fileList.length==0"><span class="el-table__empty-text">暂无数据</span></div>
				<el-col style="padding: 10px;margin: 5px" :xl="3" :lg="3" :md="4" :sm="6" :xs="24" v-for="item in fileList" :key="item.folderId"
						@dblclick="openFolder(item)">
					<div style="text-align: center;">
						<el-icon style="font-size: 40px;">
							<el-icon-folder-opened/>
						</el-icon>
					</div>
					<div style="text-align: center;font-size: 16px;font-weight: 600;text-overflow: ellipsis;width: 100%;overflow: hidden;white-space: nowrap;" :title="item.folderName">
						{{ item.folderName }}
					</div>
				</el-col>
			</el-row>
		</div>
	</el-card>
</template>

<script>
export default {
	data() {
		return {
			fileList: [],
			timer:null
		}
	},
	created() {
		clearInterval(this.timer)
		this.timer = null
	},
	beforeUnmount() {
		clearInterval(this.timer);
		this.timer = null
	},
	mounted() {
		this.getMyPublicFolderInRoleForDesk();
		this.setTimer();
	},
	methods: {
		async reLoadPublicFile()
		{
			this.getMyPublicFolderInRoleForDesk();
		},
		getMorePublicFile(){
			this.$nextTick(() => {
				this.$router.replace({
					path: '/file/public',
				})
			})
		},
		openFolder(item)
		{
			this.$nextTick(() => {
				this.$router.replace({
					name: 'Public Folder',
					params:{
						openFolderId:item.folderId,
						openFolderName:item.folderName,
						openParentId:item.parentId
					}
				})
			})
		},
		async getMyPublicFolderInRoleForDesk() {
			var res = await this.$API.file.publicFile.getMyPublicFolderInRoleForDesk.get();
			if (res.code == 200) {
				this.fileList = res.data
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		setTimer() {
			if(this.timer == null) {
				this.timer = setInterval( () => {
					this.getMyPublicFolderInRoleForDesk();
				}, this.$TOOL.data.get("MSG_TIME"))
			}
		}
	}
}
</script>
<style scoped>
:deep(.el-card__header){
	background: rgba(64, 158, 255, 0.6);
	color: white;
	padding: 10px 20px 10px 20px;
}
</style>
